<template>
  <div>
    <div>姓名： {{name}}</div>
    <div>年龄： {{age}}</div>
    <div>年龄： {{sex}}</div>
    <div>爱好： {{play}}</div>
    <button @click="updateSex">修改姓别</button>
    <button @click="updateAge">修改年龄</button>
    <button @click="sonFunction">调用父组件的方法</button>
    <button @click="publish">通知其他兄弟们</button>
  </div>
</template>

<script>
import { EventBus } from "../event-bus.js";
export default {
  name: 'son',
  props:{
    name: {
      type: String,
      default: 'spark'
    },
    age: {
      type: Number,
      default: 26
    },
    sex: {
      type: String,
      default: '女'
    }
  },
  data() {
    return{
      play: '打篮球'
    }
  },
  methods:{
    updateSex () {
      this.$emit("update:sex",'1')
    },
    updateAge () {
      this.age++
      this.$emit("update:age",this.age)
    },
    sonFunction() {
      this.$emit("fatherFunction",'我被调用了')
    },
    son2(param) {
      this.play = param
    },
    publish() {
      EventBus.$emit('tellSon','吃饭了兄弟们')
    }
  }
}
</script>

